<?php
namespace app\index\controller;


use \think\Request;
use \think\Db;
use think\Config;
use think\Controller;
use think\Loader;
use app\Base;
use \think\response\Json;
class Common extends Controller
{

	/**
	 * @writer:yangjian
	 * @DateTime:2018-03-07T20:08:10+0800
	 * @rewriter:xx
	 * @rewriter_date:YY-MM-DD
	 * @description:TOKEN验证
	 * @param:
	 * @return 
	 */
    public function _initialize()
    {
        $request = \think\Request::instance();
    	$header  = request()->header();
    	$token 	 = $header['token'];
    	$from  	 = $header['from'];
    	$method	 = $header['method'];
    	$tag = false;
    	if($method!=='login'||$method!=='register'){
    		//获取数据库TOKEN  （若TOKEN设置过存入缓存可缓存获取）
	        $id 	 = input('supplier_id');
			$Re = Db::name('supplier')->where('id',$id)->find();
			if($Re){
				if($from=='SHOPAPP'){
					if($token==$Re['app_token']){
						$tag = turn;
					} 
				}
				if($from=='SHOPAPP'){
					if($token==$Re['web_token']){
						$tag = turn;
					} 
				}
			}
    	}else{
    		$tag = turn;
    	}
        if(!$tag){    
        	$result = Config::get('code.tokenfalse');
        	echo json_encode($result);
    		exit();
        }
    }
	
}
